package com.demo.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wang
 */
public class RequestHeaderUtil {
  private RequestHeaderUtil() {
  }

  /**
   * 获取全部请求头
   *
   * @param request
   * @return
   */
  public static Map<String,String> getAllRequestHeader(HttpServletRequest request) {
    Enumeration<String> headerNames = request.getHeaderNames();
    Map<String,String> map = new HashMap<>();
    while (headerNames.hasMoreElements()) {
      String key = headerNames.nextElement();
      //根据名称获取请求头的值
      String value = request.getHeader(key);
      map.put(key, value);
    }
    return map;
  }
}
